package panels;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;
import classes.SelectionMode;

public class TileSelectionMenuPanel extends javax.swing.JPopupMenu implements ActionListener, MouseListener {

	/**
	 * This is used to represent all the tile different selection modes
	 */
	private static final long serialVersionUID = 1L;
	
	private JRadioButton	selectedBtn = null;	
	private JRadioButton	buttons[] = new JRadioButton[SelectionMode.values().length];

	private	ButtonGroup	group = new ButtonGroup();
	
	public TileSelectionMenuPanel() {
		int i;
		JRadioButton	B;
		for(i=0; i<SelectionMode.values().length; i++) {
			B = new JRadioButton( SelectionMode.values()[i].toString() );
			if (i==0) {	
				B.setSelected(true);
				selectedBtn = B;
			} else {
				B.setSelected(false);
			}
			group.add(B);
			this.add(B);
			B.addActionListener(this);
			this.addMouseListener(this);
		}
		this.setVisible(false);
		this.setEnabled(true);
		this.setSize(100,200);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		this.setVisible(false);
		this.selectedBtn = (JRadioButton) e.getSource();
		System.out.println("Selection = " + getSelection().toString());
	}
	
	public SelectionMode getSelection() {
		return SelectionMode.valueOf(this.selectedBtn.getText());
	}
	
	public void setSelected(SelectionMode M) {
		buttons[M.ordinal()].setSelected(true);
	}

	

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
	}

}
